﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WebAppMatrix.Web
{
    public class MatrixBasePage : System.Web.UI.Page
    {
        protected WebAppMatrix.Data.MatrixData DataBase = WebAppMatrix.Data.MatrixData.Create();
        private MatrixPageType pageType = MatrixPageType.Authorization;
        /// <summary>
        /// 页面类型（默认是需要验证的，如果不需要验证，请在构造函数中设置为MatrixPageType.Anonymous）
        /// </summary>
        public MatrixPageType PageType
        {
            get
            {
                return this.pageType;
            }
            set
            {
                this.pageType = value;
            }
        }

        private Entity.Security.MatrixUser userEntity = null;
        /// <summary>
        /// 当前登陆的用户
        /// </summary>
        public Entity.Security.MatrixUser UserEntity
        {
            get { return userEntity; }
        }

        protected override void OnInit(EventArgs e)
        {
            if (this.PageType == MatrixPageType.Authorization)
            {
                //未授权
                if (!this.Request.IsAuthenticated)
                {
                    //返回登陆页面
                    WebAppMatrix.Security.Security.RedirectToLoginPage();
                }
            }
            
            base.OnInit(e);
        }
    }
}
